<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="租户Id" prop="id">
        <el-input v-model="queryParams.id" placeholder="请输入租户平台Id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="运营Id" prop="tenantId">
        <el-input v-model="queryParams.tenantId" placeholder="请输入编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="网站" prop="domain">
        <el-input v-model="queryParams.domain" placeholder="请输入网站" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="域名属性" prop="domainProperty">
        <el-input v-model="queryParams.domainProperty" placeholder="请输入域名属性" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="联系方式" prop="contactInformation">
        <el-input v-model="queryParams.contactInformation" placeholder="请输入联系方式" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="接入模式" prop="accessModel">
        <el-select v-model="queryParams.accessModel" clearable placeholder="请选择">
          <el-option label="未接入" :value="0"></el-option>
          <el-option label="已接入" :value="1"></el-option>
        </el-select>
        <!-- <el-input v-model="queryParams.accessModel" placeholder="请输入接入模式" clearable @keyup.enter.native="handleQuery" /> -->
      </el-form-item>
      <!-- <el-form-item label="生成好的cname" prop="cname">
        <el-input v-model="queryParams.cname" placeholder="请输入生成好的cname" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="cname后缀" prop="cnamePrefix">
        <el-input v-model="queryParams.cnamePrefix" placeholder="请输入cname后缀" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="创建人" prop="createUser">
        <el-input v-model="queryParams.createUser" placeholder="请输入创建人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="修改人" prop="updateUser">
        <el-input v-model="queryParams.updateUser" placeholder="请输入修改人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否删除 1-是 0-否" prop="isDel">
        <el-input v-model="queryParams.isDel" placeholder="请输入是否删除 1-是 0-否" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          v-hasPermi="['system:domain:query']">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          v-hasPermi="['system:domain:query']">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:domain:add']">新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:domain:edit']">修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:domain:remove']">删除</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:domain:export']">导出</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :disabled="multiple"
          @click="setSaveTag('domainlabelBatchAddList')"
          v-hasPermi="['system:domain:selectLabelByDomainId']">批量打标签</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :disabled="multiple"
          @click="domain_funcName = 'domainlabelBatchDeleteList'; saveTag()"
          v-hasPermi="['system:domain:selectLabelByDomainId']">批量删除标签</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :disabled="multiple"
          @click="RemarkVisible = true" v-hasPermi="['system:domain:batchDomainRemark']">批量备注</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :disabled="multiple"
          @click="netSetSourceStatus1" v-hasPermi="['system:domain:batchDomainSource']">批量回源</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :disabled="multiple" @click="netSetExamine2"
          v-hasPermi="['system:domain:batchDomainCheck']">批量审核不通过</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table title="主列表" size="mini" v-loading="loading" :data="domainList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" title="租户平台" align="center" prop="id" width="80" />
      <el-table-column label="ID" title="运营平台" align="center" prop="tenantId" width="80" />
      <el-table-column label="租户名称" title="租户名称" align="center" prop="tenantName" />
      <!-- <el-table-column label="编号" align="center" prop="code" /> -->
      <el-table-column label="网站" title="域名及标签" align="center" prop="domain">
        <template slot-scope="scope">
          {{ scope.row.domain }}
          <el-button v-for="(item, index) in (scope.row.serviceDomainlabelVoList || []).map(e => e.labelName)"
            :key="index" type="primary" size="mini" style="padding: 1px;margin: 0 2px;">{{ item }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="域名属性" align="center" prop="domainProperty">
        <template slot-scope="scope">
          <el-button
            v-for="(item, index) in (scope.row.domainProperty || '').split(',').map(e => dictArr_domain_map[e] || e)"
            :key="index" type="primary" size="mini" style="padding: 1px;margin: 0 2px;">{{ item }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="联系方式" align="center" prop="contactInformation" />
      <el-table-column label="审核状态" align="center" prop="auditStatus" width="80">
        <template slot-scope="scope">
          <!-- @click="domainCheck_OnOff = true; domainCheck_Form = { id: scope.row.id, domain: scope.row.domain, auditStatus: scope.row.auditStatus }" -->
          <!-- <el-tag>标签一</el-tag><el-tag type="success">标签二</el-tag><el-tag type="info">标签三</el-tag><el-tag type="warning">标签四</el-tag><el-tag type="danger">标签五</el-tag> -->
          <el-tag :type="{ 0: 'primary', 1: 'success', 2: 'danger' }[scope.row.auditStatus] || 'info'">
            {{ domainCheck_opt[scope.row.auditStatus] || scope.row.auditStatus }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="备案状态" align="center" prop="registeredStatus" width="80">
        <template slot-scope="scope">
          <el-tag :type="{ 0: 'primary', 1: 'success', 2: 'danger' }[scope.row.registeredStatus] || 'info'">{{
            { 0: '待定', 1: '已备案', 2: '未备案' }[scope.row.registeredStatus] || scope.row.registeredStatus }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="IP" align="center" prop="">
        <template slot-scope="scope">
          <el-button v-for="(item, index) in (scope.row.serviceIpVoList || [])" :key="index" type="primary" size="mini"
            style="padding: 1px;margin: 0 2px;" v-if="index < 3">{{ item.ip }}</el-button>
          <el-button type="success" size="mini" style="padding: 1px;margin: 0 2px;">({{ (scope.row.serviceIpVoList ||
            []).length }})</el-button>
        </template>
      </el-table-column>
      <el-table-column label="线路" align="center" prop="">
        <template slot-scope="scope">
          <el-button v-for="(item, index) in (scope.row.lineMaintenanceVOS || [])" :key="index" type="primary"
            size="mini" style="padding: 1px;margin: 0 2px;" v-if="index < 3">{{ item.lineName }}</el-button>
          <el-button type="success" size="mini" style="padding: 1px;margin: 0 2px;"
            v-if="(scope.row.lineMaintenanceVOS || []).length">({{
              (scope.row.lineMaintenanceVOS || []).length }})</el-button>
        </template>
      </el-table-column>

      <el-table-column label="状态" title=" 0：正常 1：宕机" align="center" prop="status" width="80">
        <template slot-scope="scope">
          {{ { 0: 'Up', 1: 'down' }[scope.row.status] || scope.row.status }}
        </template>
      </el-table-column>
      <el-table-column label="分配方式" align="center" prop="distributionType" width="80">
        <template slot-scope="scope">
          <el-tag
            :type="{ 0: 'primary', 1: 'success', 2: 'success', 3: 'success' }[scope.row.registeredStatus] || 'info'">
            {{ { 0: '未分配', 1: '自动', 2: '人工', 3: '自动,人工' }[scope.row.distributionType] || scope.row.distributionType }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <!-- <el-table-column label="是否回源： 0 不回  1 回" align="center" prop="sourceStatus" />
      <el-table-column label="接入模式" align="center" prop="accessModel" />
      <el-table-column label="生成好的cname" align="center" prop="cname" />
      <el-table-column label="cname后缀" align="center" prop="cnamePrefix" />
      <el-table-column label="创建人" align="center" prop="createUser" />
      <el-table-column label="修改人" align="center" prop="updateUser" />
      <el-table-column label="是否删除 1-是 0-否" align="center" prop="isDel" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="getDomainSelectTag(scope.row)"
            v-hasPermi="['system:domain:edit']">标签</el-button> -->
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:domain:edit']">修改</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-edit" @click="manage_getData(scope.row, scope)"
            v-hasPermi="['system:domain:manager']">管理</el-button>
          <!-- <el-button size="mini" type="danger" style="padding:5px" icon="el-icon-delete"
            @click="handleDelete(scope.row)" v-hasPermi="['system:domain:remove']">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改域名信息对话框 -->
    <el-dialog data-title="修改 废弃" :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="租户平台Id" prop="tenantId">
          <el-input v-model="form.tenantId" placeholder="请输入租户平台Id" />
        </el-form-item>
        <el-form-item label="编号" prop="code">
          <el-input v-model="form.code" placeholder="请输入编号" />
        </el-form-item>
        <el-form-item label="网站" prop="domain">
          <el-input v-model="form.domain" placeholder="请输入网站" />
        </el-form-item>
        <el-form-item label="域名属性" prop="domainProperty">
          <el-select :value="form.domainProperty ? form.domainProperty.split(',') : []"
            @change="e => form.domainProperty = e.join(',')" multiple clearable placeholder="请选择">
            <el-option v-for="item in dictArr_domain" :key="item.dictValue" :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联系方式" prop="contactInformation">
          <el-input v-model="form.contactInformation" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="接入模式" prop="accessModel">
          <!-- <el-input v-model="form.accessModel" placeholder="请输入接入模式" /> -->
          <!-- { 0: '未接入', 1: '已接入' } -->
          <el-select v-model="form.accessModel" clearable placeholder="请选择">
            <el-option label="未接入" :value="0"></el-option>
            <el-option label="已接入" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生成好的cname" prop="cname">
          <el-input v-model="form.cname" placeholder="请输入生成好的cname" />
        </el-form-item>
        <el-form-item label="cname后缀" prop="cnamePrefix">

          <el-select :value="form.cnamePrefix ? form.cnamePrefix.split(',') : []"
            @change="e => form.cnamePrefix = e.join(',')" multiple clearable placeholder="请选择">
            <el-option v-for="item in dictArr_cname" :key="item.dictValue" :label="item.dictLabel"
              :value="item.dictValue">
            </el-option>
          </el-select>
          <el-input v-model="form.cnamePrefix" placeholder="请输入cname后缀" />
        </el-form-item>
        <el-form-item label="创建人" prop="createUser">
          <el-input v-model="form.createUser" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="修改人" prop="updateUser">
          <el-input v-model="form.updateUser" placeholder="请输入修改人" />
        </el-form-item>
        <el-form-item label="是否删除 1-是 0-否" prop="isDel">
          <el-input v-model="form.isDel" placeholder="请输入是否删除 1-是 0-否" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="'域名管理'" :visible.sync="manage_OnOff" width="80%">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="概览信息" name="first" v-hasPermi="['system:domain:getDomainOverview']">
          <el-form label-width="120px" :model="manage_data" :rules="manage_rules" ref="manage_data">
            <el-form-item label="域名信息:">
              {{ manage_data.domain }}
            </el-form-item>
            <el-form-item label="回源状态:">
              {{ { 0: '未回源', 1: '回源' }[manage_data.sourceStatus] }}
              <!-- <el-switch v-model="manage_data.sourceStatus" :active-value="1" active-text="回源" inactive-text="未回源"
                :inactive-value="0" @change="isDomainSource = true"></el-switch> -->
              <!-- {{ { 0: '失败', 1: '成功', 2: '执行中' }[manage_data.sourceOperationStatus] }} -->
            </el-form-item>
            <el-form-item label="接入状态:">
              {{ { 0: '未接入', 1: '已接入' }[manage_data.accessModel] }}
            </el-form-item>
            <el-form-item label="ip异常替换:">
              <!-- {{ { 0: '不替换', 1: '替换' }[manage_data.autoReplace] }} -->
              <el-switch v-model="manage_data.autoReplace" :active-value="1" active-text="替换" inactive-text="不替换"
                :inactive-value="0" @change="isAutoReplace = true">
              </el-switch>
            </el-form-item>
            <el-form-item label="审核状态:">
              <el-radio-group v-model="manage_data.auditStatus" @change="isAuditStatus = true">
                <el-radio-button v-for="(item, index) in Object.entries(domainCheck_opt)" :key="index"
                  :label="+item[0]">{{
                    item[1]
                  }}</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item v-if="manage_data.auditStatus === 2" label="驳回原因" prop="auditNote">
              <el-input v-model="manage_data.auditNote" placeholder="请输入驳回原因" @change="isAuditStatus = true"
                v-hasPermi="['system:domain:batchDomainRemark']" />
            </el-form-item>
            <el-form-item label="备案信息:">
              {{ { 0: '待定', 1: '已备案', 2: '未备案' }[manage_data.registeredStatus] || manage_data.registeredStatus }}
              <!-- 备案未锁定 备案已锁定 -->
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="netSetDomainCheck2('manage_data')">确 定</el-button>
              <el-button @click="getDomainOverview(() => { $message({ message: '刷新成功', type: 'success' }) })">刷
                新</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="IP调度" name="second">
          <el-form style="padding:10px 0" :inline="true">
            <el-form-item label="标签">
              <el-button
                v-for="(item, index) in ((domainList[manage_index] || {}).serviceDomainlabelVoList || []).map(e => e.labelName)"
                :key="index" type="primary" size="mini" style="padding: 1px;margin: 0 2px;">{{ item }}</el-button>
              <el-button type="primary" @click="getDomainSelectTag(domainList[manage_index])"
                v-hasPermi="['system:domain:selectLabelByDomainId']" :disabled="manage_disabled">选择标签</el-button>
              <el-button type="primary" :loading="domainAssignIP_loading" @click="domainAssignIP"
                v-hasPermi="['system:domain:assignIP']" :disabled="manage_disabled">重新调度</el-button>
            </el-form-item>
            <el-form-item label="选择CNAME前缀">
              <el-cascader :value="newcnamePrefix" @change="e => cnamePrefix = e.length ? e[e.length - 1] : ''"
                :options="cnamePrefixOpt" :props="{ expandTrigger: 'hover' }"></el-cascader>
            </el-form-item>
            <el-button type="primary" :loading="addCnamePrefix_loading" @click="addCnamePrefix"
              :disabled="manage_disabled">保存CNAME前缀</el-button>
            <el-button type="primary" @click="getAssignIPList">刷新</el-button>
          </el-form>
          <el-table :data="manage_ipArr" border style="width: 100%;" size="medium">
            <el-table-column prop="id" label="id" width="80">
            </el-table-column>
            <el-table-column prop="domain" label="域名" width="180">
            </el-table-column>
            <el-table-column label="ip">
              <template slot-scope="scope">{{ scope.row.ip }} <span style="font-size:80%"
                  v-if="scope.row.idcMotorRoom">({{ scope.row.idcMotorRoom
                  }})</span> <span style="font-size:80%">(使用次数:{{ scope.row.useNum }})</span></template>
            </el-table-column>
            <el-table-column label="机器码" align="center" prop="machineCode" />
            <!-- <el-table-column prop="ip" label="宕机或超过10G">
        </el-table-column> -->
            <el-table-column prop="domainProperty" label="域名类型" width="80">
              <template slot-scope="scope" v-if="scope.row.domainProperty">
                <el-button
                  v-for="(item, index) in (scope.row.domainProperty || '').split(',').map(e => dictArr_domain_map[e] || e)"
                  :key="index" type="primary" size="mini" style="padding: 1px;margin: 0 2px;">{{ item }}</el-button>
              </template>
            </el-table-column>
            <el-table-column prop="line" label="线路">
              <template slot-scope="scope">
                <el-button v-for="(item, index) in (scope.row.lineMaintenanceVOS || [])" :key="index" type="primary"
                  size="mini" style="padding: 1px;margin: 0 2px;" v-if="index < 3">{{ item.lineName }}</el-button>
                <el-button type="success" size="mini" style="padding: 1px;margin: 0 2px;"
                  v-if="(scope.row.lineMaintenanceVOS || []).length">({{
                    (scope.row.lineMaintenanceVOS || []).length }})</el-button>
              </template>
            </el-table-column>
            <el-table-column prop="status" label="使用状态" width="80" align="center">
              <template slot-scope="scope"> <el-tag
                  :type="{ 0: 'primary', 1: 'success' }[scope.row.status] || 'info'">{{ {
                    0: '未使用', 1: '使用中'
                  }[scope.row.status] }}</el-tag></template>
            </el-table-column>
            <el-table-column prop="synStatus" label="同步状态" title="0：未同步1：同步中2:已同步 3:同步失败" width="80" align="center">
              <template slot-scope="scope"><el-tag
                  :type="{ 0: 'primary', 1: 'warning', 2: 'success', 3: 'danger' }[scope.row.synStatus] || 'info'">{{
                    { 0: '未同步', 1: '同步中', 2: '已同步', 3: '同步失败' }[scope.row.synStatus]
                  }}</el-tag></template>
            </el-table-column>
            <el-table-column prop="ipStatus" label="UP/Down" title="状态 0：正常 1：宕机" width="80" align="center">
              <template slot-scope="scope"><el-tag
                  :type="{ 0: 'success', 1: 'danger' }[scope.row.ipStatus] || 'info'">{{
                    { 0: 'UP', 1: 'Down' }[scope.row.ipStatus] }}</el-tag></template>
            </el-table-column>
            <el-table-column prop="assignType" label="分配方式" title="1 自动  2 手动" width="80" align="center">
              <template slot-scope="scope"><el-tag
                  :type="{ 1: 'primary', 2: 'success' }[scope.row.assignType] || 'info'">{{ {
                    1: '自动', 2: '手动'
                  }[scope.row.assignType] }}</el-tag></template>
            </el-table-column>
            <el-table-column prop="createTime" label="添加时间" width="160" align="center">
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="60">
              <template slot-scope="scope">
                <el-button v-if="scope.row.isDel === 0" @click="domainipDelete(scope.row)" type="text"
                  v-hasPermi="['system:domainip:remove']" size="small" :disabled="manage_disabled">删除</el-button>
                <el-button v-else @click="domainipRevertDelete(scope.row)" type="text" size="small"
                  :disabled="manage_disabled">撤销删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="manage_query.pageNum" :page-sizes="[10, 20, 50, 100]" :page-size="manage_query.pageSize"
            layout="total, sizes, prev, pager, next, jumper" :total="manage_ip_total">
          </el-pagination>
          <!-- <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" /> -->
          <el-form style="padding:10px 0 0" :inline="true" :model="formInline" class="demo-form-inline" title="手动分配IP">
            <el-form-item label="搜索类型">
              <el-select v-model="formInline.searchType" placeholder="活动区域">
                <el-option label="按照标签搜索" value="1"></el-option>
                <el-option label="按照基础信息搜索" value="2"></el-option>
                <el-option label="按照属性搜索" value="3"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="标签id列表" v-if="formInline.searchType == 1">
              <!-- <el-input v-model="formInline.labelIdList" placeholder="List<Long>"></el-input> -->
              <el-button @click="setSaveTag('formInline_tag')">选择搜索标签</el-button>
              <el-button v-for="item in formInline.labelIdListCn" :key="item" type="primary" size="mini"
                style="padding: 1px;margin: 0 2px;">{{ item }}</el-button>

            </el-form-item>
            <el-form-item label="机柜位置" v-if="formInline.searchType == 2">
              <el-input v-model="formInline.location" placeholder="机柜位置"></el-input>
            </el-form-item>
            <el-form-item label="IDC机房" v-if="formInline.searchType == 2">
              <el-input v-model="formInline.IDC" placeholder="IDC机房"></el-input>
            </el-form-item>
            <el-form-item label="ip模糊搜索" v-if="formInline.searchType == 2">
              <el-input v-model="formInline.ipStr" placeholder="ip模糊搜索"></el-input>
            </el-form-item>
            <el-form-item label="属性Id" v-if="formInline.searchType == 3">
              <el-button @click="optIp_OnOff = true">选择IP属性</el-button>
              <el-button v-for="item in formInline.propertyIdListCn" :key="item" type="primary" size="mini"
                style="padding: 1px;margin: 0 2px;">{{ item }}</el-button>
              <!-- <el-input v-model="formInline.propertyIdList" placeholder="List<Long>"></el-input> -->
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="domainGetIpList" v-hasPermi="['system:domain:getIpList']"
                :disabled="manage_disabled">查询</el-button>
            </el-form-item>
          </el-form>
          <el-form title="域名手动分配IP" :inline="true" label-width="60px">
            <el-form-item label="选择IP">
              <el-select style="width: 400px;" v-model="manage_find_ids2" multiple collapse-tags placeholder="请选择">
                <el-option v-for="item in manage_find" :key="item.id" :label="item.ip" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-button type="primary" @click="domainManualAssign" :loading="domainManualAssign_loading"
              :disabled="!manage_find_ids2.length || manage_disabled"
              v-hasPermi="['system:domain:manualAssign']">域名手动分配IP!</el-button>
            </el-form-item>
          </el-form>
          <el-table v-if="0" :data="manage_find" border style="width: 100%" @selection-change="handleSelectionChange2">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column prop="id" label="id" width="80">
            </el-table-column>
            <!-- <el-table-column prop="domain" label="域名" width="180">
            </el-table-column> -->
            <el-table-column prop="ip" label="ip">
            </el-table-column>
            <!-- <el-table-column prop="ip" label="宕机或超过10G">
        </el-table-column> -->
            <el-table-column prop="domainProperty" label="域名类型">
            </el-table-column>
            <el-table-column prop="line" label="线路">
              <template slot-scope="scope">
                <el-button v-for="(item, index) in (scope.row.lineMaintenanceVOS || [])" :key="index" type="primary"
                  size="mini" style="padding: 1px;margin: 0 2px;" v-if="index < 3">{{ item.lineName }}</el-button>
                <el-button type="success" size="mini" style="padding: 1px;margin: 0 2px;"
                  v-if="(scope.row.lineMaintenanceVOS || []).length">({{
                    (scope.row.lineMaintenanceVOS || []).length }})</el-button>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="status" label="暂停启用" title="0 暂停  1 启用">
              <template slot-scope="scope">{{ { 0: '暂停', 1: '启用' }[scope.row.status] }}</template>
            </el-table-column>
            <el-table-column prop="synStatus" label="同步状态" title="0 未同步 1已同步">
              <template slot-scope="scope">{{ { 0: '未同步', 1: '已同步' }[scope.row.synStatus] }}</template>
            </el-table-column> -->
            <el-table-column prop="ipStatus" label="UP/Down" title="状态 0：正常 1：宕机">
              <template slot-scope="scope">{{ { 0: 'UP', 1: 'Down' }[scope.row.ipStatus] }}</template>
            </el-table-column>
            <!-- <el-table-column prop="assignType" label="分配方式" title="1 自动  2 手动">
              <template slot-scope="scope">{{ { 1: '自动', 2: '手动' }[scope.row.assignType] }}</template>
            </el-table-column>
            <el-table-column prop="createTime" label="添加时间">
            </el-table-column>
            <el-table-column label="操作">
            </el-table-column> -->
          </el-table>
          <!-- v-model="cnamePrefix" :value="newcnamePrefix" @change="e => cnamePrefix = e.join(',')" -->

          <el-button type="primary" :loading="synchronizationIp_loading" @click="synchronizationIp"
            v-hasPermi="['system:domain:synchronizationIp']">同步</el-button>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
    <el-dialog title="批量备注" :visible.sync="RemarkVisible">
      <el-input v-model="batchDomainRemarkStr" autocomplete="off"></el-input>
      <div slot="footer" class="dialog-footer">
        <el-button @click="RemarkVisible = false">取 消</el-button>
        <el-button type="primary" @click="netSetRemark">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="'打标签'" :visible.sync="tag_OnOff">
      <el-card class="box-card">
        <p class="text">标签作为域名和IP直接匹配的中间媒介</p>
        <p class="text">域名所打标签和节点池所打标签，每个类型标签取交集，如果都有交集则匹配，否则不匹配</p>
      </el-card>
      <el-form label-width="150px">

        <el-form-item label="请选择标签"><el-button type="text" @click="handlerTag(1)">管理标签<i
              class="el-icon-right"></i></el-button></el-form-item>
        <el-form-item v-for="(item, i0) in tag_opt" :key="i0" :label="item.labelTypeName">
          <el-button v-for="(tag, i1) in item.domainLabelVoList" :type="tag.checkedState ? 'primary' : ''" size="mini"
            :key="i1"
            @click="tag_opt[i0].domainLabelVoList[i1].checkedState = tag_opt[i0].domainLabelVoList[i1].checkedState == 1 ? 0 : 1">{{
              tag.labelName }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="saveTag('domainlabelAddList')">确定</el-button>
          <el-button type="primary" @click="tag_OnOff=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog :visible.sync="optIp_OnOff">
      <el-form label-width="120px">
        <div class="tab2" v-for="(item, i) in optIpArr" :key="i">
          <el-form-item :label="item.name">
            <!-- 多选 -->
            <template v-if="item.chooseType == 1">
              <el-checkbox-group v-model="item.select">
                <el-checkbox v-for="rad in item.sysTwoPropettyVModelList" :key="rad.id" :label="rad.id">{{ rad.name
                  }}</el-checkbox>
              </el-checkbox-group>
            </template>
            <!-- 单选 -->
            <template v-else>
              <el-radio-group v-model="item.select" :disabled="item.edit == 2">
                <el-radio v-for="rad in item.sysTwoPropettyVModelList" :key="rad.id" :label="rad.id">{{
                  rad.name }}</el-radio>
              </el-radio-group>
            </template>
          </el-form-item>
        </div>
        <el-form-item>
          <el-button type="primary" @click="setPropertyIdList">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
          <el-button @click="optIpArr = JSON.parse(optIpStr)">清 空</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog title="提示" :visible.sync="dialogFormVisible">
      <el-form :model="batchForm" ref="batchForm" :rules="batchRules" label-width="80px">
        <el-form-item label="驳回原因" prop="auditNote">
          <el-input v-model="batchForm.auditNote" autocomplete="off"
            v-hasPermi="['system:domain:batchDomainRemark']"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="netSetExamine2Save('batchForm')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>


import {
  batchDomainCheck,
  batchDomainSource,
  batchDomainRemark,
  domainCheck,
  domainlabelBatchAddList, // 批量打标签
  domainlabelBatchDeleteList, // 批量删除标签
  domainlabelAddList, //打标签
  domainSelectLabelByDomainId,
  getDomainOverview, // 管理概览
  getAssignIPList, // 查询分配的Ip
  domainAssignIP, // 1.10.14 重新调度分配ip
  synchronizationIp,// 同步IP
  domainGetIpList, //手动分配Ip搜索
  domainipDelete, // 逻辑删除关联的ip
  domainipRevertDelete, // 撤销删除关联的ip
  domainManualAssign, // 手动分配ip
  getAllPrefix,// 选择cname后缀列表
  addCnamePrefix, // 保存cname后缀列表
  listDomain, getDomain, delDomain, addDomain, updateDomain,
  domainIpReplace, //ip替换
} from "@/api/system/domain";
import { selectLabelByPoolId, addPoolTag, } from "@/api/system/pool";
import { getLabelType, } from "@/api/system/label";
import { listPagePropetty, } from "@/api/system/one/propetty";
export default {
  name: "Domain",
  data() {
    return {
      batchRules: { auditNote: [{ required: true, message: '请填写驳回原因', trigger: 'blur' },] },
      batchForm: { auditNote: '' },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 域名信息表格数据
      domainList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        id: null,
        pageNum: 1,
        pageSize: 10,
        tenantId: null,
        code: null,
        domain: null,
        domainProperty: null,
        contactInformation: null,
        auditStatus: null,
        registeredStatus: null,
        status: null,
        distributionType: null,
        sourceStatus: null,
        accessModel: null,
        cname: null,
        cnamePrefix: null,
        createUser: null,
        updateUser: null,
        isDel: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      dialogFormVisible: false,
      batchDomainRemarkStr: '',
      domainCheck_Form: { id: '', auditStatus: '' },
      // domainCheck_OnOff: false,
      domainCheck_opt: { 0: '审核中', 1: '通过', 2: '不通过' },
      tag_opt: [],
      tag_opt_str: '[]',
      tag_OnOff: false,
      domain_funcName: '',
      domainIds: '',

      manage_OnOff: false,
      manage_id: 0,
      manage_data: {},
      manage_rules: { auditNote: [{ required: true, message: '请填写驳回原因', trigger: 'blur' },] },
      manage_query: { pageSize: 10, pageNum: 1 },
      manage_ipArr: [],
      manage_ip_total: 0,
      manage_row: {},
      manage_index: -1,
      formInline: { searchType: '' },
      activeName: "first",
      manage_find: [],
      manage_find_ids2: [],
      dictArr_domain: [],// 域名属性字典
      dictArr_domain_map: {},
      dictArr_cname: [],
      checkboxGroup1: [],
      checkboxGroup2: '',
      optIpArr: [],
      optIp_OnOff: false,

      cnamePrefixOpt: [],
      cnamePrefix: '',

      synchronizationIp_loading: false,
      addCnamePrefix_loading: false,
      domainManualAssign_loading: false,
      domainAssignIP_loading: false,

      isAutoReplace: false,
      isAuditStatus: false,

      RemarkVisible: false,
    };
  },
  computed: {
    manage_disabled: function () { // sourceOperationStatus
      return this.manage_data.sourceStatus === 1 || this.manage_data.sourceOperationStatus === 2
    },
    tag_opt_val: function () {
      const tmp = this.tag_opt.map(v => {
        return v.domainLabelVoList.filter(v0 => v0.checkedState).map(v0 => v0.labelId).join(',')
      }).filter(v => v.length).join(',')
      return tmp ? tmp.split(',') : []
    },
    tag_opt_name: function () {
      const tmp = this.tag_opt.map(v => {
        return v.domainLabelVoList.filter(v0 => v0.checkedState).map(v0 => v0.labelName).join(',')
      }).filter(v => v.length).join(',')
      return tmp ? tmp.split(',') : []
    },
    newcnamePrefix: function () {
      // cnamePrefix
      if (this.cnamePrefix && this.cnamePrefixMap && this.cnamePrefix in this.cnamePrefixMap) {
        return [this.cnamePrefixMap[this.cnamePrefix], this.cnamePrefix]
      } else return this.cnamePrefix
    }
  },
  created() {
    //console.log('权限', this.$auth.hasPermi('system:domain:selectLabelByDomainId'))
    this.getList();
    if (this.$auth.hasPermi('system:domain:selectLabelByDomainId')) this.get_tag_opt()
    getLabelType({ dictType: 'domain_name_properties' }).then(e => {
      const dictArr_domain_map = {}
      e.data.forEach(v => { dictArr_domain_map[v.dictValue] = v.dictLabel })
      this.dictArr_domain = e.data
      this.dictArr_domain_map = dictArr_domain_map
    })
    getLabelType({ dictType: 'cname_prefix_type' }).then(e => {
      this.dictArr_cname = e.data
    })
    listPagePropetty().then(response => {
      // ip 属性
      const propettyList = response.data || [];
      console.log(propettyList)
      propettyList.forEach(item => {
        if (item.chooseType == 1) {
          item.select = [];
        } else {
          item.select = '';
        }
        if (Array.isArray(item.sysTwoPropettyVModelList))
          item.sysTwoPropettyVModelList.forEach(obj => {
            if (item.name === "带宽" && obj.unit) obj.name += obj.unit
            obj.checked = false;
          });
      });
      const optData = { 0: {} }
      propettyList.forEach(item => {
        optData[0][item.id] = item.name
        optData[item.id] = {}
        if (Array.isArray(item.sysTwoPropettyVModelList))
          item.sysTwoPropettyVModelList.forEach(obj => {
            optData[item.id][obj.id] = obj.name
          });
      });
      this.optIpData = optData
      this.optIpStr = JSON.stringify(propettyList)
      this.optIpArr = JSON.parse(this.optIpStr)
    });
    getAllPrefix({ status: 0 }).then(e => {
      // cnamePrefix
      const cnamePrefixMap = {}
      const cnamePrefixOpt = e.data.map(v => {
        const { labelType: value1, labelTypeName: label, serviceCnamePrefixVoList: children } = v
        return {
          value: value1, label, children: (children || []).map(v1 => {
            const { cnamePrefix: value, cnameName: label } = v1
            cnamePrefixMap[value] = value1
            return { value, label }
          })
        }
      })
      this.cnamePrefixMap = cnamePrefixMap
      this.cnamePrefixOpt = cnamePrefixOpt
    })
  },
  methods: {
    get_tag_opt() {
      return domainSelectLabelByDomainId().then(e => { // 库 poolLabelVoList // domainLabelVoList
        const tag_opt = e.data.map(e => {
          if (!Array.isArray(e.domainLabelVoList)) e.domainLabelVoList = [];
          e.domainLabelVoList.forEach(v => { v.checkedState = false })
          return e
        })
        //this.tag_opt_str = JSON.stringify(tag_opt)
        this.tag_opt = tag_opt
        // console.log('tag_opt=', tag_opt)
        // return tag_opt
      })
    },
    addCnamePrefix() {
      this.addCnamePrefix_loading = true
      var formdata = new FormData();
      formdata.append("id", this.manage_id);
      formdata.append("cnamePrefix", this.cnamePrefix);
      addCnamePrefix(formdata).then(e => {
        this.$message({ message: e.msg, type: 'success' })
        this.getList();
      }).finally(() => {
        this.addCnamePrefix_loading = false
      })
    },
    domainipRevertDelete(e) {
      console.log(e)
      var formdata = new FormData();
      formdata.append("id", e.id);
      domainipRevertDelete(formdata).then(e => {
        this.$message({ message: e.msg, type: 'success' })
        this.getAssignIPList()
      })
    },
    domainipDelete(e) {
      console.log(e)
      var formdata = new FormData();
      formdata.append("id", e.id);
      domainipDelete(formdata).then(e => {
        this.$message({ message: e.msg, type: 'success' })
        this.getAssignIPList()
      })
    },
    setPropertyIdList() {
      let oForm = [];
      this.optIpArr.forEach(item => {
        if (item.select) (Array.isArray(item.select) ? item.select : [item.select]).forEach(twoid => {
          oForm.push({
            ipId: this.ipAdmin_edit_ipid,
            twoPropettyId: twoid,
            twoPropettyName: this.optIpData[item.id][twoid],
            onePropettyId: item.id,
            onePropettyName: this.optIpData[0][item.id],
            type: 2,
          });
        });
      });
      this.formInline.propertyIdListCn = oForm.map(v => v.twoPropettyName)
      this.formInline.propertyIdList = oForm.map(v => v.twoPropettyId)
      this.optIp_OnOff = false
      console.log()
    },
    domainManualAssign() {
      this.domainManualAssign_loading = true
      domainManualAssign({
        domainId: this.manage_id, serviceIpVoList: this.manage_find_ids2.map(v => ({ id: v, ip: this.manage_find_idip[v] }))
      }).then(e => {
        this.$message({ message: e.msg, type: 'success' })
        this.manage_find_ids2 = []
        this.getAssignIPList()
      }).finally(() => {
        this.domainManualAssign_loading = false
      })
    },
    fnchange(e) {
      console.log('e=', e)
    },
    handleClick() { },
    domainGetIpList() {
      const { searchType, labelIdList, location, IDC, propertyIdList, ipStr } = this.formInline
      var formdata = new FormData();
      formdata.append("searchType", searchType);
      //[104531,104532]

      // `?searchType=${searchType}&labelIdList=${labelIdList.join(',')}`||
      const fn = (e) => {
        this.manage_find = e.data;
        const manage_find_idip = {};
        e.data.forEach(v => { manage_find_idip[v.id] = v.ip })
        this.manage_find_idip = manage_find_idip
      }
      if (searchType == 1) domainGetIpList({ searchType, labelIdList }).then(fn)
      if (searchType == 2) domainGetIpList({ searchType, location: location || undefined, IDC: IDC || undefined, ipStr: ipStr || undefined }).then(fn)
      if (searchType == 3) domainGetIpList({ searchType, propertyIdList }).then(fn)
    },
    domainAssignIP() {//重新调度
      this.domainAssignIP_loading = true
      var formdata = new FormData();
      formdata.append("domainId", this.manage_id);
      // content-type:
      domainAssignIP(formdata).then(e => {
        this.$message({ message: e.msg, type: 'success' })
        this.getAssignIPList()
      }).finally(() => {
        this.domainAssignIP_loading = false
      })
    },
    synchronizationIp() {
      this.synchronizationIp_loading = true
      var formdata = new FormData();
      formdata.append("domainId", this.manage_id);

      synchronizationIp(`domainId=${this.manage_id}` || formdata).then(e => {
        this.$message({ message: e.msg, type: 'success' })
        this.getList();
      }).finally(() => {
        this.synchronizationIp_loading = false
        // setTimeout(() => { this.synchronizationIp_loading = false }, 999)
      })
    },
    manage_getData(row, scope) {
      console.log(scope)
      // this.domainList[this.manage_index]
      this.manage_index = scope.$index
      // 管理读取数据 
      this.manage_row = row// JSON.parse(JSON.stringify(row))
      this.cnamePrefix = row.cnamePrefix
      this.manage_OnOff = true
      this.manage_id = row.id
      this.manage_find_ids2 = []
      this.getDomainOverview()
      this.getAssignIPList()
      this.formInline = { searchType: '' }
      this.optIpArr = JSON.parse(this.optIpStr)
    },
    getDomainOverview(fn) {

      if (this.$auth.hasPermi('system:domain:getDomainOverview'))
        getDomainOverview(this.manage_id).then(e => {
          this.manage_data = e.data;
          if (typeof fn === 'function') fn()
        })
    },
    handleSizeChange(e) {
      console.log('handleSizeChange', e)
      this.manage_query.pageSize = e
      this.manage_query.pageNum = 1
      this.getAssignIPList()
    },
    handleCurrentChange(e) {
      this.manage_query.pageNum = e
      this.getAssignIPList()
    },
    getAssignIPList() {
      if (this.$auth.hasPermi('system:domainip:getAssignIPList'))
        getAssignIPList({ ...this.manage_query, domainId: this.manage_id }).then(e => {
          this.manage_ipArr = e.rows
          this.manage_ip_total = e.total
        })
    },
    setSaveTag(domain_funcName, optStr) {// 打开标签界面
      this.domain_funcName = domain_funcName;
      // const tag_opt = JSON.parse(this.tag_opt_str);
      
      // const optMap = {}
      // if (optStr && typeof optStr === 'string') {
      //   optStr.split(',').filter(v => v).forEach(v => { optMap[v] = 1 })
      // }
      // tag_opt.forEach(v => { v })
      // this.tag_opt = tag_opt
      this.tag_OnOff = true
      this.get_tag_opt()
    },
    saveTag() {
      // domain_funcName === 'domainlabelBatchDeleteList';saveTag()
      console.log('save')
      if (this.domain_funcName === 'domainlabelAddList') {
        domainlabelAddList({ domainId: this.domainIds, labelIdList: this.tag_opt_val }).then(e => {
          this.$message({ message: e.msg, type: 'success' });
          this.getList();
          this.tag_OnOff = false
        })
      } else if (this.domain_funcName === 'domainlabelBatchAddList') { // 批量添加tag
        domainlabelBatchAddList({ domainIdList: this.ids, labelIdList: this.tag_opt_val }).then(e => {
          this.$message({ message: e.msg, type: 'success' });
          this.getList();
          this.tag_OnOff = false
        })
      } else if (this.domain_funcName === 'domainlabelBatchDeleteList') {// 批量删除tag
        domainlabelBatchDeleteList({ domainIdList: this.ids, labelIdList: this.tag_opt_val }).then(e => {
          this.$message({ message: e.msg, type: 'success' });
          this.getList();
          this.tag_OnOff = false
        })
      } else if (this.domain_funcName === 'formInline_tag') {
        this.formInline.labelIdListCn = JSON.parse(JSON.stringify(this.tag_opt_name))
        this.formInline.labelIdList = JSON.parse(JSON.stringify(this.tag_opt_val))
        this.tag_OnOff = false
      } else {
        this.$message({
          message: '没有选择类型',
          type: 'warning'
        });
      }
      // domainIdList
    },
    handlerTag(v) {
      if (v > 0) {
        this.TagOpen = false;
        this.$router.push("/common/label");
      } else {
        this.TagOpen = false;
        this.getList();
      }
    },
    getDomainSelectTag(row) {
      console.log(row)
      this.domain_funcName = 'domainlabelAddList' // 设置保存时执行的函数
      this.domainIds = row.id
      domainSelectLabelByDomainId({ domainId: row.id }).then(e => {
        // 域名 
        console.log(e)
        const tagMap = {};
        (row.serviceDomainlabelVoList || []).forEach(v => {
          tagMap[v.labelId] = v.labelName
        })

        this.tag_opt = e.data.map(v => {
          (v.domainLabelVoList || []).forEach(v => {
            if (v.labelId in tagMap)
              v.checkedState = 1
          })
          return v
        })
        this.tag_OnOff = true
      })
    },
    tagS() {

    },
    tagClick(tag, i0, i1) {
      console.log('onClick', this.tag_opt[i0].domainLabelVoList[i1].checkedState)
      // tag.domainLabelVoList[i1].checkedState = tag.domainLabelVoList[i1].checkedState == 1 ? 0 : 1
      this.tag_opt[i0].domainLabelVoList[i1].checkedState = this.tag_opt[i0].domainLabelVoList[i1].checkedState == 1 ? 0 : 1
    },
    netSetExamine2() { // 批量审核不通过
      this.dialogFormVisible = true
      this.batchForm.auditNote = ''
    },
    netSetExamine2Save(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // alert('submit!');
          this.dialogFormVisible = false
          batchDomainCheck({ domainIdList: this.ids, auditStatus: 2, auditNote: this.batchForm.auditNote }).then((res) => {
            this.$modal.msgSuccess(res.msg);
            this.getList();
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });

    },
    // netSetSourceStatus1() { // 批量回源
    //   batchDomainSource({ domainIdList: this.ids, sourceStatus: 1 }).then((res) => {
    //     this.$modal.msgSuccess(res.msg);
    //     this.getList();
    //   })
    // },
    netSetRemark() {
      batchDomainRemark({ domainIdList: this.ids, remark: this.batchDomainRemarkStr }).then((res) => {
        this.$modal.msgSuccess(res.msg);
        this.RemarkVisible = false
        this.batchDomainRemarkStr = ''
        this.getList();
      })

    },
    netSetDomainCheck() {
      const { id, auditStatus } = this.domainCheck_Form
      var formdata = new FormData();
      formdata.append("id", id);
      formdata.append("auditStatus", auditStatus);
      domainCheck(formdata).then(e => {
        // this.domainCheck_OnOff = false
        this.getList();
      })
    },
    netSetDomainCheck2(formName) {// 保存 manage_data.sourceStatus
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const { id, auditStatus, autoReplace, auditNote, sourceStatus } = this.manage_data
          if (this.isAutoReplace) {
            const formdata = new FormData();
            formdata.append("id", id);
            formdata.append("autoReplace", autoReplace || 0);
            domainIpReplace(formdata).then(e => {
              // this.domainCheck_OnOff = false
              this.isAutoReplace = false
              this.$modal.msgSuccess(e.msg);
              // this.getList();
              this.getDomainOverview()
            })
          }
          if (this.isAuditStatus) {
            const formdata = new FormData();
            formdata.append("id", id);
            formdata.append("auditStatus", auditStatus || 0);
            formdata.append("auditNote", auditNote || '');
            domainCheck(formdata).then(e => {
              // this.domainCheck_OnOff = false
              this.isAuditStatus = false
              this.$modal.msgSuccess(e.msg);
              this.getList();
              this.getDomainOverview()
            })
          }
          if (this.isDomainSource) {
            batchDomainSource({ domainIdList: [id], sourceStatus }).then((res) => {
              this.$modal.msgSuccess(res.msg);
              this.isDomainSource = false
              this.$modal.msgSuccess(e.msg);
              this.getDomainOverview()
            })
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    /** 查询域名信息列表 */
    getList() {
      this.loading = true;
      listDomain(this.queryParams).then(response => {
        this.domainList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tenantId: null,
        code: null,
        domain: null,
        domainProperty: null,
        contactInformation: null,
        auditStatus: null,
        registeredStatus: null,
        status: null,
        distributionType: null,
        remark: null,
        sourceStatus: null,
        accessModel: null,
        cname: null,
        cnamePrefix: null,
        updateTime: null,
        createTime: null,
        createUser: null,
        updateUser: null,
        isDel: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleSelectionChange2(selection) {
      this.manage_find_ids2 = selection.map(item => ({ id: item.id, ip: item.ip }))

      // this.single2 = selection.length !== 1
      // this.multiple2 = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加域名信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDomain(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改域名信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            var formdata = new FormData();
            updateDomain(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDomain(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除域名信息编号为"' + ids + '"的数据项？').then(function () {
        return delDomain(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/domain/export', {
        ...this.queryParams
      }, `domain_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
